var pub = {
	//基础地址
	baseUrl: 'http://localhost:8080',
	//成功弹窗
	promptSuccess: function (title) {
		Swal.mixin({
			toast: true,
			position: 'top-end',
			showConfirmButton: false,
			timer: 4000
		}).fire({
			type: "success",
			title
		})
	},
	//失败弹窗
	promptError: function (title) {
		Swal.mixin({
			toast: true,
			position: 'top-end',
			showConfirmButton: false,
			timer: 4000
		}).fire({
			type: "error",
			title
		})
	},
	//封装的post请求
	post: function (path, data, success) {
		$.ajax({
			url:this.baseUrl + path,
			dataType:"json",
			type:"post",
			// async:"true/false",
			data,
			success,
			error:function(){
				Swal.mixin({
					toast: true,
					position: 'top-end',
					showConfirmButton: false,
					timer: 4000
				}).fire({
					type: "error",
					title: "请重新登录"
				})
			}
		})
	},
	//封装的get请求
	get: function (path, data, success) {
		$.ajax({
			url:this.baseUrl + path,
			dataType:"json",
			type:"get",
			// async:"true/false",
			data,
			success,
			error:function(){
				Swal.mixin({
					toast: true,
					position: 'top-end',
					showConfirmButton: false,
					timer: 4000
				}).fire({
					type: "error",
					title: "请重新登录"
				})
			}
		})
	},
	//封装的自定义表单，用于跳转页面时携带token
	diyForm: function(url, method, paramObj){
		var form = document.createElement("form")
		form.setAttribute("action", url)
		form.setAttribute("method", method)
		Object.keys(paramObj).forEach(function (key) {
			var input = document.createElement("input")
			input.setAttribute("name", key)
			input.setAttribute("value", paramObj[key])
			form.appendChild(input)
			console.log(form)
		})
		//放入body
		document.getElementsByTagName("body")[0].appendChild(form)
		form.submit()
	}

}
export default pub